<html>
<head><meta charset="utf-8"><title>try and type disambiguation · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html">try and type disambiguation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213092056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092056">(Oct 12 2020 at 22:23)</a>:</h4>
<p>I just ran into a situation where I would love to have <code>try</code>. And while I would like to avoid writing a type signature, I could live with doing so.</p>



<a name="213092067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092067">(Oct 12 2020 at 22:23)</a>:</h4>
<p>It would still be more convenient than "wrap in closure and call".</p>



<a name="213092126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092126">(Oct 12 2020 at 22:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/try.20and.20type.20disambiguation/near/213092067">said</a>:</p>
<blockquote>
<p>It would still be more convenient than "wrap in closure and call".</p>
</blockquote>
<p>look at this beauty <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> cooked up <a href="https://github.com/rust-lang/rust/pull/77862/files#diff-4b76d999d0f2e74f6df3724a36a6b96302b16968a2f7af48d2b4c08048f8f871R80">https://github.com/rust-lang/rust/pull/77862/files#diff-4b76d999d0f2e74f6df3724a36a6b96302b16968a2f7af48d2b4c08048f8f871R80</a></p>



<a name="213092129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092129">(Oct 12 2020 at 22:24)</a>:</h4>
<p>I feel like, as long as we leave the door open for better inference in the future, it'd be fine if the common case needs a type signature.</p>



<a name="213092135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092135">(Oct 12 2020 at 22:24)</a>:</h4>
<p>for some definition of beauty ;)</p>



<a name="213092166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092166">(Oct 12 2020 at 22:25)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="1977">@T-lang</span> Other than type inference, what are the blockers for try at the moment?</p>



<a name="213092173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213092173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213092173">(Oct 12 2020 at 22:25)</a>:</h4>
<p>personally (and I'm sure the door closed on this a while ago) I would rather have <code>try_block!</code> and <code>try_some!</code> in std than as a language feature</p>



<a name="213094097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213094097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213094097">(Oct 12 2020 at 22:54)</a>:</h4>
<p>I think the open questions are still where error conversion can happen in them.  And we probably can't just say "only when there's no conversion", because loosening that later would probably end up being inference breaks.</p>



<a name="213094107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213094107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213094107">(Oct 12 2020 at 22:54)</a>:</h4>
<p>(Sorry, I still haven't done that write-up <span aria-label="slight frown" class="emoji emoji-1f641" role="img" title="slight frown">:slight_frown:</span>)</p>



<a name="213096244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213096244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213096244">(Oct 12 2020 at 23:32)</a>:</h4>
<p>Interestingly, a stable <code>try{}</code> would allow us to stabilize <code>Try</code> in <code>FnOnce</code>/<code>SliceIndex</code> "mention but not implement or use methods" style: <a href="https://github.com/rust-lang/rust/pull/77877/files#diff-63d6b948e93db9ae17b8a9a43cfbf6736d653692cd71a5cd777078c91e882354R1663">https://github.com/rust-lang/rust/pull/77877/files#diff-63d6b948e93db9ae17b8a9a43cfbf6736d653692cd71a5cd777078c91e882354R1663</a></p>
<p>Though it's not obvious to me that we're sure enough about the future that that would actually be a <em>good</em> idea.</p>



<a name="213151212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213151212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213151212">(Oct 13 2020 at 13:10)</a>:</h4>
<p>something <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> brought up:</p>
<blockquote>
<p>I did hesitate between try blocks and this hand-rolled try_some! macro a lot, and the thing is, I wanted to have that is_macro_rules early escape branch, by early returning None. And try blocks have no mechanism to early return other than ?, which means that with a try block the code becomes:</p>
</blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">try</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">ast</span><span class="p">.</span><span class="n">macro_rules</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">None</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>Which can be made to "look" better by being more hacky: <code>return None?;</code>, abusing the fact the return is actually unreachable.</p>
<p>None of these options pleased me, which is the main reason for this being at a draft stage.</p>



<a name="213152192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213152192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213152192">(Oct 13 2020 at 13:18)</a>:</h4>
<p>I really want <code>break 'a</code> to a block for this stuff</p>



<a name="213162484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213162484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213162484">(Oct 13 2020 at 14:27)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> That would be something like this, right?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">try</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">ast</span><span class="p">.</span><span class="n">macro_rules</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">yeet</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213162548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213162548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213162548">(Oct 13 2020 at 14:28)</a>:</h4>
<p>basically, yes</p>



<a name="213162591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213162591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213162591">(Oct 13 2020 at 14:28)</a>:</h4>
<p>petition to make <code>yeet</code> a keyword <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="213165128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213165128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213165128">(Oct 13 2020 at 14:42)</a>:</h4>
<p>I would love to see the yeet (fail/throw/etc) proposal revived as well.</p>



<a name="213188987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213188987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213188987">(Oct 13 2020 at 17:24)</a>:</h4>
<p>I'm still a pretty big fan of try</p>



<a name="213188998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213188998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213188998">(Oct 13 2020 at 17:24)</a>:</h4>
<p>I would love that writeup, <span class="user-mention" data-user-id="125270">@scottmcm</span></p>



<a name="213208304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213208304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213208304">(Oct 13 2020 at 19:50)</a>:</h4>
<p>yeet that RFC straight into the master branch</p>



<a name="213218752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213218752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213218752">(Oct 13 2020 at 21:23)</a>:</h4>
<p>Can <code>yeet</code> be an optional keyword replacement of whatever is actually chosen? \s</p>



<a name="213223091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213223091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213223091">(Oct 13 2020 at 22:08)</a>:</h4>
<p><span class="user-mention" data-user-id="247082">@Sebastian Malton</span> I'll get right on that after I finish <a href="https://users.rust-lang.org/t/rename-vec-to-arr/49698/9?u=scottmcm"><code>Arr&lt;T&gt;</code></a>   /s</p>



<a name="213223554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/try%20and%20type%20disambiguation/near/213223554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/try.20and.20type.20disambiguation.html#213223554">(Oct 13 2020 at 22:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/try.20and.20type.20disambiguation/near/213223091">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="247082">Sebastian Malton</span> I'll get right on that after I finish <a href="https://users.rust-lang.org/t/rename-vec-to-arr/49698/9?u=scottmcm"><code>Arr&lt;T&gt;</code></a>   /s</p>
</blockquote>
<p>didn't you hear? It's called <code>Buffer</code> now!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>